define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'task/cancle_order/index',
                    add_url: 'task/cancle_order/add',
                    edit_url: 'task/cancle_order/edit',
                    del_url: 'task/cancle_order/del',
                    multi_url: 'task/cancle_order/multi',
                    table: 'shop_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'order_sno', title: __('Order_sno')},
                        {field: 'task_sno', title: __('Task_sno')},
                        {field: 'task_type', title: __('Task_type'),searchList: {
                            "1":__('精刷单'),
                            "2":__('隔日单'),
                            "3":__('流量单')
                        },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            },operate:false},
                        {field: 's.shop_name', title: __('Shop_name'),operate:"LIKE"},
                        {field: 'shop_username', title: __('商家名称'),operate:false},
                        {field: 'nusername', title: __('撤销操作人'),operate:false},
                        {field: 'real_money', title: __('实付金额'),operate:false},
                        {field: 'insert_price', title: __('拍下价格'),operate:false},
                        {field: 'u.uid', title: __('Uid')},
                        {field: 'u.username', title: __('Paike_name')},
                        {field: 'status', title: __('Status'),searchList: {
                                "0":__('已拍下'),
                                "1":__('未审核'),
                                "2":__('已审核'),
                                "3":__('已上传'),
                                "4":__('已复查'),
                                "5":__('已付款'),
                                "6":__('已下单'),
                                "7":__('待发货'),
                                "8":__('待好评'),
                                "9":__('已发货'),
                                "10":__('已好评'),
                                "11":__('待追评'),
                                "12":__('已追评'),
                                "13":__('已完成'),
                        },formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                if(value=="" || value==null){
                                    value = value;
                                }else{
                                    value = value.toString();
                                }
                                var index = keys.indexOf(value);
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            },operate:false},
                        {field: 'order_state', title: __('撤销操作'), searchList: {"0":__('正常'),"1":__('已撤销'),"2":__('已回收')},formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'flag', title: __('是否插旗'),searchList: {"1":__('未插旗'),"2":__('已插旗')},formatter:function(value,row,index){
                                var keys = typeof this.searchList === 'object' ? Object.keys(this.searchList) : [];
                                var index = keys.indexOf(value.toString());
                                value = value === null ? '' : value.toString();
                                var display = index > -1 ? this.searchList[value] : null;
                                var icon = typeof this.icon !== 'undefined' ? this.icon : null;
                                if (!display) {
                                    display = __(value.charAt(0).toUpperCase() + value.slice(1));
                                }
                                var html = '<span class="text">' + (icon ? '<i class="' + icon + '"></i> ' : '') + display + '</span>';

                                return html;
                            }},
                        {field: 'flag_remarks', title: __('Flag_remarks'),operate:false},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime,operate:false},

                    ]
                ]
            });




            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});